<script src="./assets/yunjii/app_m.js"></script>
<script>
    var hashsalt = <?php echo $addsalt_js ?>;
    // 默认点亮第N个ID
    var active_ClassID = <?php echo $shop_cid ?>;
    getGoodsPro(active_ClassID);

    function selectGoods(tid, cid) {
        window.history.pushState({}, '', `./?shop_cid=${cid}&tid=${tid}`);
        updatePayButton(tid, cid);
    }

    function changeQuantity(change) {
        var numInput = document.getElementById('num');
        var currentValue = parseInt(numInput.value, 10);
        if ((currentValue + change) >= 1) {
            numInput.value = currentValue + change;
        }
    }

    function updatePayButton(tid, cid) {
        var total = calculateTotal(tid);
        if (tid && cid && total !== null) {
            document.getElementById('payButton').href = `./?mod=buy&cid=${cid}&tid=${tid}`;
            document.getElementById('payButton').querySelector('span').innerText = `立即支付￥${total.toFixed(2)}`;
        } else {
            document.getElementById('payButton').href = "javascript:void(0)";
            document.getElementById('payButton').querySelector('span').innerText = "立即支付￥请选择商品";
        }
    }

    function calculateTotal(tid) {
        // 这里假设有一个函数来计算总价
        // 根据实际逻辑实现这个函数
        return parseFloat(document.querySelector(`.goods_box[data-goods_id="${tid}"] .goods_price`).innerText.replace(/[^0-9.-]+/g,"")) * parseInt(document.getElementById('num').value, 10);
    }

    // 在页面加载完成后更新支付按钮
    window.onload = function() {
        var urlParams = new URLSearchParams(window.location.search);
        var selectedTid = urlParams.get('tid');
        var selectedCid = urlParams.get('cid');
        if (selectedTid && selectedCid) {
            updatePayButton(selectedTid, selectedCid);
        }
    };
</script>
<script>
    // 获取当前页面的url参数
    var _URL = new URL(location.href);
    var _P1 = _URL.search;
    if (_P1 == '?buyok=1') {
        // 跳转到?mod=query
        window.location.href = './?mod=query&type=0&qq=&page=1';
    }
</script>